package com.android.lovely.ui.adapter

import android.net.Uri
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.android.lovely.R
import com.android.lovely.databinding.ItemShotsAddBinding
import com.android.lovely.databinding.ItemShotsBinding
import com.android.lovely.ext.loadWithPlaceholder
import com.android.lovely.framework.BaseAdapter
import com.kotlin.extensions.inflater.LayoutInflaterExt.layoutInflater
import com.kotlin.extensions.view.ViewExt.clickable

class ItemOrderAdapter : BaseAdapter<Uri, ItemShotsBinding>() {

    override fun bindViewWithHolderDetails(holder: ViewHolder, item: Uri?, binding: ItemShotsBinding, position: Int) {
        binding.image.loadWithPlaceholder(item, R.drawable.icon_rectangle_holder)
        binding.remove.clickable {
            item?.let { uri -> delete(uri) }
            onItemClick?.invoke(item, position)
        }
    }
}

class ItemAddAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() {

    var onItemClick: (() -> Unit)? = null

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
        return object : RecyclerView.ViewHolder(ItemShotsAddBinding.inflate(parent.layoutInflater, parent, false).root) {}
    }

    override fun getItemCount(): Int {
        return 1
    }

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        holder.itemView.clickable {
            onItemClick?.invoke()
        }
    }

}